package datasv.courseProduce_datasv;

import po.CourseBasicPO;
import resultmessage.CourseProduceRM;
import data.datafactory.DatabaseOperator;

public class UpdateCourseBasic {
	public static void main(String[] args) {
		System.out.println(new UpdateCourseBasic()
				.updateCourseBasic(new CourseBasicPO("00101130010", "test", 1,
						5, 2, 3, "xianlin", "001", "00101", 120)));
	}

	public CourseProduceRM updateCourseBasic(CourseBasicPO po) {
		return updateInSql(po);
	}

	public CourseProduceRM updateInSql(CourseBasicPO po) {
		String collegeID = po.getCollegeID();
		DatabaseOperator op = new DatabaseOperator("college" + collegeID);
		if (!op.ifDatabaseExist()
				|| !op.ifIDExist("course_list", po.getCourseId())) {
			return CourseProduceRM.COURSE_ID_NOT_EXSIT;
		}
		int num = AddCourseBasic.columnNum;
		String[][] info = new String[num][2];
		info[0][0] = AddCourseBasic.columnName[0];
		info[0][1] = po.getCourseId();
		info[1][0] = AddCourseBasic.columnName[1];
		info[1][1] = po.getCampus();
		info[2][1] = po.getDepartment();
		info[2][0] = AddCourseBasic.columnName[2];
		info[3][1] = Integer.toString(po.getCredit());
		info[3][0] = AddCourseBasic.columnName[3];
		info[4][1] = Integer.toString(po.getSemester());
		info[4][0] = AddCourseBasic.columnName[4];
		info[5][1] = Integer.toString(po.getMaxStudentNum());
		info[5][0] = AddCourseBasic.columnName[5];
		info[6][1] = po.getCourseName();
		info[6][0] = AddCourseBasic.columnName[6];
		info[7][1] = Integer.toString( po.getHeadCredit());
		info[7][0] = AddCourseBasic.columnName[7];
		info[8][1] = Integer.toString(po.getTailCredit());
		info[8][0] = AddCourseBasic.columnName[8];
		for (int i = 0; i < num; i++) {
			if (!op.setOneInform(info[0][1], info[i][1], "course_list",
					info[i][0])) {
				return CourseProduceRM.COURSEBASIC_NOT_EXSIT;
			}
		}
		return CourseProduceRM.SUCCESS;
	}
}
